<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>首页导航</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            background: rgba(41, 120, 166, 1);
        }

        #header {
            height: 44px;
            padding: 0 35px;
            background: rgba(90, 194, 255, 1);
            box-sizing: content-box;
        }

        .nav {
            height: 16px;
            font-size: 15px;
            font-weight: 500;
            color: rgba(255, 255, 255, 0.8);
            line-height: 15px;
        }

        .nav-active {
            position: relative;
            height: 16px;
            font-size: 16px;
            font-weight: 500;
            color: rgba(255, 255, 255, 1);
            line-height: 14px;
            overflow: visible;
        }

        .nav-active::after {
            content: "";
            position: absolute;
            left: 50%;
            bottom: -8px;
            width: 20px;
            height: 3px;
            transform: translateX(-50%);
            background: rgba(255, 255, 255, 1);
            border-radius: 2px;
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <header id="header" data-flex="main:justify cross:center">
            <div class="nav" v-for="item,index in nav" :class="{ 'nav-active': index === current }"
                @click="handleNav(index)">
                {{ item.title }}
            </div>
        </header>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm;
    var headerH;
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        fnInit();
    };
    // 需要的参数
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                current: 0,
                nav: [
                    {
                        title: '课程',
                        to: 'course/index'
                    },
                    {
                        title: '班级',
                        to: 'class/index'
                    },
                    {
                        title: '习题报告',
                        to: 'class/select_model',
                        param: {
                            reportType: 1,
                            from: 'index'
                        }
                    },
                    {
                        title: '跟读报告',
                        to: 'class/select_model',
                        param: {
                            reportType: 2,
                            from: 'index'
                        }
                    }
                ]
            }
        });
        // 获取header的高度
        headerH = $api.offset($api.byId('header')).h;
        openList();
    }

    function openList() {
        var frames = [];
        var names = [
            vm.nav[0].to,
            vm.nav[1].to
        ];
        for (var i = 0; i < names.length; i++) {
            var temp = {};
            temp.name = 'tab_index_frm' + i;
            temp.url = '../' + names[i] + '.html';
            temp.pageParam = {
                type: ''
            };
            frames.push(temp);
        }
        var tParam = {
            name: 'tab_index_frms',
            frames: frames,
            preload: 1,
            index: 0,
            scrollEnabled: false,
            rect: {
                x: 0,
                y: headerH,
                w: 'auto',
                h: api.winHeight - headerH - localStorage.safeBottom
            }
        };

        var callback = function (ret) {
            vm.current = ret.index;
        };
        fnOpenFrameGroup(tParam, callback);
    }

    function handleNav(index) {
        if (userIsLogin()) {
            if (index > 1) {
                fnOpenPublicWin(vm.nav[index].title, vm.nav[index].to, vm.nav[index].param);
            } else {
                vm.current = index;
                api.setFrameGroupIndex({
                    name: 'tab_index_frms',
                    scroll: true,
                    index: index
                });
            }
        }
    }

    function resetNav() {
        api.setFrameGroupIndex({
            name: 'tab_index_frms',
            scroll: true,
            index: 0
        });
    }

</script>

</html>